<template>
  <div class="index">
    <head-text titleText="现场核销"></head-text>
    <div class="list-content">
      <div class="filter-area">
        <el-form ref="searchFrom" :model="searchFrom" inline label-width="80px">
          <el-form-item label="领取码：" prop="text">
            <el-input v-model="searchFrom.text" size="mini"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" plain @click="getList" size="mini"
              >查询</el-button
            >
            <el-button type="danger" plain @click="rest" size="mini"
              >重置</el-button
            >
          </el-form-item>
        </el-form>
      </div>
      <el-card class="box-card" v-if="isShow">
        <div class="status">
          <el-row>
            <el-col :span="12"
              ><h3>
                订单状态：<span style="margin-left:8px;">{{
                  data.orderStatus | orderStatusFilter
                }}</span>
              </h3></el-col
            >
            <el-col :span="12">
              <h3>
                领取状态：<span style="margin-left:8px;">{{
                  data.pickUpTime || "未领取"
                }}</span>
              </h3></el-col
            >
          </el-row>
        </div>
        <div class="form-content">
          <div class="title"><i class="el-icon-user"></i>买家信息</div>
          <p>
            账号：<i> {{ data.customerAccount }}</i>
          </p>
          <p>
            昵称：<i> {{ data.nickname }}</i>
          </p>
          <p>
            联系电话：<i> {{ data.orderPhone }}</i>
          </p>
          <div class="title"><i class="el-icon-document"></i>订单信息</div>
          <el-row>
            <el-col :span="8">
              <span
                >订单号：<i> {{ data.orderSn }}</i></span
              >
            </el-col>
            <el-col :span="8">
              <span
                >支付流水号：<i> {{ data.serialNumber }}</i></span
              >
            </el-col>
            <el-col :span="8">
              <span
                >支付方式：<i> {{ data.paymentMethod | payFilter }}</i></span
              >
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <span
                >取餐地点：<i> {{ data.pickUpPlace }} </i></span
              >
            </el-col>
            <el-col :span="8">
              <span
                >订购时间：<i> {{ data.createTime }} </i></span
              >
            </el-col>
            <el-col :span="8">
              <span
                >楼层：<i> {{ data.venueFloor | floorFilter }} </i></span
              >
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <span
                >关联活动：<i> {{ data.activityName }}</i>
              </span>
            </el-col>
            <el-col :span="8">
              <span
                >活动场次: <i>{{ data.activityTime }}</i>
              </span>
            </el-col>
          </el-row>
          <div class="table-content">
            <div class="title" style="margin-bottom:10px;">
              <i class="el-icon-shopping-cart-full"></i>商品信息
            </div>
            <el-table
              :data="data.orderDetailList"
              style="width: 100%"
              border
              size="mini"
            >
              <el-table-column type="index" width="50" align="center">
              </el-table-column>
              <el-table-column prop="productName" label="商品" align="center">
              </el-table-column>
              <el-table-column label="商品图" align="center" width="100">
                <template slot-scope="scope">
                  <div>
                    <img
                      :src="scope.row.imgUrl"
                      class="img-size"
                      alt=""
                      v-image-preview
                    />
                  </div>
                </template>
              </el-table-column>
              <el-table-column
                prop="productCnt"
                label="数量（份）"
                align="center"
              >
              </el-table-column>
              <el-table-column
                prop="categoryName"
                label="商品分类"
                align="center"
              >
              </el-table-column>
              <el-table-column
                prop="productPrice"
                label="单价(元)"
                align="center"
              >
              </el-table-column>
              <el-table-column
                prop="currentPrice"
                label="商品总价(元)"
                align="center"
              >
              </el-table-column>
              <el-table-column
                prop="feeMoney"
                label="折后金额(元)"
                align="center"
              >
              </el-table-column>
              <el-table-column
                prop="packingCharge"
                label="打包费"
                align="center"
              >
              </el-table-column>
            </el-table>
            <p class="mb-10">备注：{{ data.remark }}</p>
            <div class="table-total">
              <p>
                基础打包费：
                <span>
                  {{ data.basePackingCharge ? data.basePackingCharge : 0 }}
                  元</span
                >
              </p>
              <p>
                商品总计： <span> {{ data.orderMoney }} 元</span>
              </p>
              <p>
                优惠金额：<span>{{ data.discountMoney }} 元</span>
              </p>
              <p>
                实收金额：<span>{{ data.paymentMoney }} 元</span>
              </p>
            </div>
          </div>
          <div class="operate-footer">
            <el-button
              type="primary"
              @click="sub(data.orderId)"
              size="mini"
              v-if="data.orderStatus == 2 || data.orderStatus == 1"
              >确认取餐</el-button
            >
          </div>
        </div>
      </el-card>
    </div>
  </div>
</template>

<script>
import { _debounce } from "@u/debounce";
import {
  FLOOROBJ,
  DISCOUNTTYPE,
  PAYTYPE,
  ORDERSTATUS,
  SMSSTATUS
} from "@u/wordbook";
import headText from "@c/headText";
import { siteAuditApi, orderInfoApi } from "@s/api";
export default {
  name: "index",
  data() {
    return {
      data: [],
      isShow: false,
      searchFrom: {
        text: ""
      }
    };
  },
  //过滤器
  filters: {
    floorFilter(val) {
      return FLOOROBJ[val];
    },
    discountFilter(val) {
      return DISCOUNTTYPE[val];
    },
    payFilter(val) {
      return PAYTYPE[val];
    },
    orderStatusFilter(val) {
      return ORDERSTATUS[val];
    },
    SmsFilter(val) {
      return SMSSTATUS[val];
    }
  },
  methods: {
    // 重置
    rest() {
      this.$refs.searchFrom.resetFields();
    },
    view(id) {
      let json = {
        pickUpNumber: id,
        orderType: 1 // 餐饮
      };
      orderInfoApi(json).then(res => {
        this.data = res;
        this.isShow = true;
        if (this.data.orderStatus == 6 || this.data.orderStatus == 7) {
          this.$message({
            type: "warning",
            message: "商品已取消交易"
          });
        }
      });
    },
    refView(id) {
      let json = {
        pickUpNumber: id,
        orderType: 1 // 餐饮
      };
      orderInfoApi(json).then(res => {
        this.data = res;
      });
    },
    getList() {
      if (this.searchFrom.text) {
        let str = this.searchFrom.text;
        str = str.replace(/\s*/g, "");
        this.isShow = false;
        this.view(str);
      } else if (this.searchFrom.text == 1) {
        this.$message({
          type: "warning",
          message: "领取码有误！"
        });
      }
    },
    sub: _debounce(function(id) {
      this.$confirm("此操作将核销该订单?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        siteAuditApi(id).then(() => {
          let str = this.searchFrom.text;
          str = str.replace(/\s*/g, "");
          this.refView(str);
          this.$message({
            type: "success",
            message: "核销成功！"
          });
        });
      });
    })
  },
  watch: {
    "searchFrom.text": function(val) {
      if (val.trim() == "") {
        this.isShow = false;
      } else {
        // 每四位加一个空格规则，
        this.$nextTick(() => {
          this.searchFrom.text = val
            .replace(/\s/g, "")
            .replace(/....(?!$)/g, "$& ");
        });
      }
    }
  },
  components: {
    headText
  }
};
</script>
<style scoped lang="scss">
.status {
  margin: 0px 30px;
  h3 {
    margin: 10px 0;
    font-weight: 600;
    margin-right: 30px;
  }
}
.form-content {
  margin: 30px;
  font-size: 14px;
  i {
    margin: 0 5px;
    font-style: normal;
    color: #333333;
  }
  p {
    margin: 12px 0;
    font-size: 12px;
  }
  .el-col {
    margin: 12px 0;
    font-size: 12px;
  }
  h4 {
    font-weight: 600;
    margin: 20px 0;
  }
}
.table-content {
  margin: 30px 0;
}
.table-total {
  float: right;
  margin-top: 20px;
  p {
    line-height: 2;
    span {
      float: right;
      margin-left: 10px;
    }
  }
}
.operate-footer {
  clear: both;
  text-align: center;
}
.box-card {
  margin: 0 50px;
}
.img-size {
  width: 60px;
  cursor: pointer;
}
.title {
  background: #f1f1f1;
  padding: 10px;
  border-radius: 5px;
}

// 兼容移动端
@media(max-width:820px) {
    .status h3{
    font-size: 16px;
  }
.time-show{
  display: none;
}
.el-col-8 {
  width: 100%!important;
}
}
</style>
